<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>登录</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link rel="stylesheet" href="../common/common.css"/>
    <link rel="stylesheet" href="../css/Token_Start.css">
</head>
<body>
<header class="forgetPwd-head-title">
    <strong class="Token_Transaction" id="forgetBack"><img src="../img/left.png" alt=""/></strong><p>忘 记 密 码</p>
</header>

        <div class="login-box  forgetPwd-box">
            <div class="form-login">
                <form action="">
                    <ul class="login-input">
                        <li><input  placeholder="请输入邮箱" type="email" id="regstEmail"/></li>
                        <li><input  placeholder="请设置登录密码" type="password" id="regstPwd"/></li>
                        <li><input  placeholder="请设置登录密码" type="password" id="againPwd"/></li>
                        <li><p class="invited-line"><input  placeholder="请输入验证码" type="text" id="invitedCode"/></p>  <span id="verifyCode" class="gold-border">获取验证码</span></li>
                    </ul>
                </form>
                <div class="login-box-act">
                    <p><span  class="login-btn" id="registerBtn">确 定</span></p>
                </div>
                <div class="login-err">
                    <p id="tipError">信息错误</p>
                </div>
            </div>
        </div>

<script src="../js/jquery-3.2.1.min.js"></script>
<script src="../js/Token_Start.js"></script>
        <script>
            $(function () {
                $("#forgetBack").click(function(){
                    location.href="Token_login.html"
                });
                $("input").focus(function () {
                    $("#tipError").css("display","none")
                });

                //获取验证码
                $("#verifyCode").click(function(){
                    var regIptEmail=$("#regstEmail").val();
                    var regEmail=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
                    if(regIptEmail.length==0){
                        $("#tipError").html("邮箱地址不能为空").css("display","block");
                        return true;
                    }else if(!regEmail.test(regIptEmail)){
                        $("#tipError").html("请输入正确的邮箱地址").css("display","block");
                        return true;
                    }
                    //发送AJAX
                       $.ajax({
                    	type:'post',
                    	url:"/app/user_registered/forgetpass",
                        data:{"regIptEmail":regIptEmail},
                        success:function(r){
                        	if(r.code==0){
                            	$("#verifyCode").html("获取成功");
                            }else{
                            	$("#verifyCode").html("重新获取");
                            	alert(r.msg)
                            }
                        }
                    })
                });
                //注册提交 ajax
                $("#registerBtn").click(function () {
                    var regEmail=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/;
                    var regPwd= /^.*(?=.{6,})(?=.*\d)(?=.*[a-zA-Z]).*$/;
                    var regInputEmail=$("#regstEmail").val();
                    var regInputPwd=$("#regstPwd").val();
                    var regInputRepwd=$("#againPwd").val();
                    var regInvited=$("#invitedCode").val();
                    //判断邮箱
                    if(regInputEmail.length==0){
                        $("#tipError").html("邮箱地址不能为空").css("display","block");
                        return true;
                    }else if(!regEmail.test(regInputEmail)){
                        $("#tipError").html("请输入正确的邮箱地址").css("display","block");
                        return true;
                    }
                    //判断输入密码
                    if(regInputPwd.length==0){
                        $("#tipError").html("密码不能为空").css("display","block");
                        return true;
                    }else if(!regPwd.test(regInputPwd)){
                        $("#tipError").html("密码长度至少6位，包含数字和字母").css("display","block");
                        return true;
                    }
                    //判断确认密码
                    if(regInputRepwd.length==0){
                        $("#tipError").html("确认密码不能为空").css("display","block");
                        return true;
                    }else if(regInputRepwd!==regInputPwd){
                        $("#tipError").html("两次密码不一致").css("display","block");
                        return true;
                    }
                    //判断邀请码
                    if(regInvited.length==0){
                        $("#tipError").html("邀请码不能为空").css("display","block");
                        return true;
                    }
                    var more={email:regInputEmail,pwd:regInputPwd,verifyCode:regInvited};
                    console.log("more register",more);
                    $.ajax({
                        url:"/app/user_registered/forgetpwd",
                        data:more,
                        success:function(r){
                           // console.log(r);
                            if(r.code==0){
								console.log(r)
								$("#tipError").html("修改成功，请重新登录").css("display","block");
								sessionStorage.removeItem("token");
								localStorage.removeItem("token");
                            }
                        }
                    })
                });

            });

        </script>
</body>
</html>